/**
 * Created with IntelliJ IDEA.
 * Description:
 * Date: 2024-01-31
 * Time:16:12
 */
public class MyLinkedList implements ILinkedList{

    static class LinkedListNode {
        public int val;
        public LinkedListNode prev;
        public LinkedListNode next;

        LinkedListNode(int val) {
            this.val = val;
            this.prev = null;
            this.next = null;
        }
    }

    public LinkedListNode head;
    public LinkedListNode last;

    @Override
    public void addFirst(int data) {
        LinkedListNode listNode = new LinkedListNode(data);
        if(head == null) {
            head = listNode;
            last = listNode;
        } else {
            listNode.next = head;
            head.prev = listNode;
            head = listNode;
        }

    }

    @Override
    public void addLast(int data) {
        LinkedListNode node = new LinkedListNode(data);
        if(head == null) {
            head = node;
            last = node;
        } else {
            last.next = node;
            node.prev = last;
            last = node;
        }
    }
////////////////////////////////////////////////////////

    //任意位置插入,第一个数据节点为0号下标
    public boolean addIndex(int index,int data) {

    }

    public void display() {
        LinkedListNode listNode = head;
        while(listNode != null) {
            System.out.print(listNode.val + " ");
            listNode = listNode.next;
        }
    }
}
